package com.mxpio.erp.technology.controller;

import com.mxpio.erp.common.technology.entity.ItemDesignFileSignIn;
import com.mxpio.erp.common.technology.service.ItemDesignFileSignInService;
import com.mxpioframework.common.vo.Result;
import com.mxpioframework.jpa.query.Criteria;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "ItemDesignFileSignInController", description = "产品设计图档签入申请")
@RestController
@RequestMapping("/erp/common/item/designfile/signin/")
public class ItemDesignFileSignInController {

	@Autowired
	private ItemDesignFileSignInService service;

	@GetMapping("list")
	@Operation(summary = "产品设计图档签入申请列表", description = "获取产品设计图档签入申请列表", method = "GET")
	public Result<List<ItemDesignFileSignIn>> list(Criteria criteria)  {
		List<ItemDesignFileSignIn> itemDesignFileSignIns = service.list(ItemDesignFileSignIn.class, criteria);
		return Result.OK(itemDesignFileSignIns);
	}

	@GetMapping("list/{code}")
	@Operation(summary = "根据code获取产品设计图档签入申请", description = "根据code获取产品设计图档签入申请", method = "GET")
	public Result<ItemDesignFileSignIn> getById(@PathVariable(name = "code", required = true) String code) {
		ItemDesignFileSignIn signIn = service.getByIdWith( code);
		return Result.OK(signIn);
	}
	@GetMapping("page")
	@Operation(summary = "产品设计图档签入申请列表", description = "获取产品设计图档签入申请列表", method = "GET")
	public Result<Page<ItemDesignFileSignIn>> page(Criteria criteria, Integer pageSize, Integer pageNo) {
		Pageable page = PageRequest.of(pageNo-1, pageSize);
		Page<ItemDesignFileSignIn> itemDesignFileSignIns = service.listPage(ItemDesignFileSignIn.class, page, criteria);
		return Result.OK(itemDesignFileSignIns);
	}

	@PutMapping("edit")
	@Operation(summary = "编辑产品设计图档签入申请", description = "编辑产品设计图档签入申请(工作流回调 ，回写审核状态及流程实例ID)", method = "PUT")
	public Result<ItemDesignFileSignIn> edit(@RequestBody ItemDesignFileSignIn itemDesignFileSignIn) {
		service.update(itemDesignFileSignIn);
		return Result.OK(itemDesignFileSignIn);
	}
/*	@PostMapping("add")
	@Operation(summary = "新增产品设计图档签入申请", description = "新增产品设计图档签入申请", method = "POST")
	public Result<ItemDesignFileSignIn> add(@RequestBody ItemDesignFileSignIn itemDesignFileSignIn) {
		itemDesignFileSignInSerivce.save(itemDesignFileSignIn);
		return Result.OK(itemDesignFileSignIn);
	}

	@PutMapping("edit")
	@Operation(summary = "编辑产品设计图档签入申请", description = "编辑产品设计图档签入申请（全量）", method = "PUT")
	public Result<ItemDesignFileSignIn> edit(@RequestBody ItemDesignFileSignIn itemDesignFileSignIn) {
		itemDesignFileSignInSerivce.update(itemDesignFileSignIn);
		return Result.OK(itemDesignFileSignIn);
	}*/

	@GetMapping("audit_pass/{code}/{result}")
	@Operation(summary = "产品设计图档签入申请-审核结果回调", description = "产品设计图档签入申请-审核结果回调", method = "GET")
	public Result<ItemDesignFileSignIn> auditPass(@PathVariable(name = "code", required = true) String code,@PathVariable(name = "result", required = true) String result ) {
		return service.auditPass(code,result);
	}
}
